from cy_query import models

__all__ = ['MessageModel','MessageUserModel']


class MessageModel(models.Model):
    creator = models.IntegerField(db_comment='发送人用户ID',db_index=True)
    create_time = models.DateTimeField(auto_now_add=True, db_comment='创建时间')
    type = models.IntegerField(choices=((0,'normal'),(1,'system'),(2,'todo')),default=0,db_comment='消息类型(普通/系统/代办)')
    grade = models.IntegerField(default=0,db_comment='消息等级')
    title = models.CharField(max_length=32,db_comment='标题',db_index=True)
    content = models.TextField(db_comment='消息内容',default=0)
    scheduled_time = models.DateTimeField(null=True,blank=True,db_comment='定时时间')
    message_options = models.JSONField(null=True, blank=True, db_comment='消息配置')
    content_options = models.JSONField(null=True, blank=True, db_comment='内容配置')
    options = models.JSONField(null=True, blank=True, db_comment='其他配置')
    is_success = models.BooleanField(default=False,db_comment="是否发送成功")

    class Meta:
        db_table = 'messages'
        verbose_name = '消息'


class MessageUserModel(models.Model):
    message = models.ForeignKey(MessageModel,on_delete=models.CASCADE,db_comment='消息ID',db_constraint=False)
    target_creator = models.IntegerField(db_comment='接收人ID',db_index=True)
    is_read = models.BooleanField(default=False,db_comment='是否已读')
    status = models.IntegerField(choices=((0,'未开始'),(1,'进行中'),(0,'已完成')),db_comment='代办状态')
    create_time = models.DateTimeField(null=True,blank=True, db_comment='发送时间')
    message_options = models.JSONField(null=True, blank=True, db_comment='消息配置')
    content_options = models.JSONField(null=True, blank=True, db_comment='内容配置')
    options = models.JSONField(null=True, blank=True, db_comment='其他配置')
    is_success = models.BooleanField(default=False, db_comment="是否发送成功")
    is_user_delete = models.BooleanField(default=False, verbose_name='是否用户删除')

    class Meta:
        db_table = 'messages_users'
        verbose_name = '发送记录'
